// pages/hotel/index.js
const App = getApp()
const chooseLocation = requirePlugin('chooseLocation');
const api = require('../../utils/requst.js').API;
Page({
  data: {
    demandTitle:'',
    top:0,
    num:0,
    date: '2020-09-01',
    enddate: '2020-09-10',
    activeArr:[{id:"1",name:"商务"},{id:"2",name:"婚礼"}],
    array: [{id:"aa",name:"111"},{id:"aa",name:"222"},{id:"aa",name:"333"}],
    location:{name: ""},
    demandType:'1',
    tid:'',
    tname:'',
    teacherProfe:'',
    tProfe:{'1':'主持人','2':'化妆师','3':'摄影师','4':'摄像师','5':'统筹师'},
    areaName:'清镇市百花新城2栋',
    isAlone:'',
    total_fee:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    let top = 58+App.globalData.systemInfo.statusBarHeight + App.globalData.menuButton.height + (App.globalData.menuButton.top - App.globalData.systemInfo.statusBarHeight)*2
    console.log(e.isAlone)
    console.log(e.price)
    this.setData({top:top,tid:e.id,tname:e.name,teacherProfe:e.teacherProfe,isAlone:e.isAlone,total_fee:e.price})
  },
  pushInfo(){
    api.saveDemand({
      demandTitle:this.data.demandTitle,
      demandType:this.data.demandType,
      teacherId:this.data.tid,
      transactionType:this.data.teacherProfe,
      scheduledStartTime:this.data.date+' 00:00:00',
      scheduledEndTime:this.data.enddate+' 00:00:00',
      areaName:this.data.areaName,
      isAlone:this.data.isAlone,
      userId:wx.getStorageSync('token')
    }).then(res=>{
        if(res.data.code==200){
          wx.navigateTo({
            url: '../pay/index?total_fee='+this.data.total_fee,
          })
        }
    })
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const location = chooseLocation.getLocation();
    if(location){
      this.setData({location})
    }
  },
  change(e){
    console.log(e.detail)
  },
  activeChange(e){
    this.setData({
      demandType:this.data.activeArr[e.detail].id
    })
  },
  transactionChange(e){
    this.setData({
      transactionType:this.data.transactionArr[e.detail].id
    })
  },
  bindDateChange: function(e) {
    this.setData({
      date: e.detail.value
    })
  },
  endChange: function(e) {
    this.setData({
      enddate: e.detail.value
    })
  },
  lenChange(e){
    let value = e.detail.value;

    this.setData({num:value.length,demandTitle:value})
  },
  tohotelDetail(){
    wx.navigateTo({
      url: '../hotelDetail/index',
    })
  },
  goGetLocation(){
    const key = 'N4PBZ-G2UWQ-X545S-GES3K-HS7J5-RXBNX'; //使用在腾讯位置服务申请的key
    const referer = '金刚统筹-用户端'; //调用插件的app的名称
    const category = '饭店,酒店酒楼';
    wx.navigateTo({
      url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&category=${category}`
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})